#include <bits/stdc++.h>
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    auto func = [&](int x) {
        int cnt1 = 0, cnt2 = 0;
        while(a % x == 0) a /= x, cnt1++;
        while(b % x == 0) b /= x, cnt2++;
        ans += abs(cnt1 - cnt2);
    } ;
    func(2), func(3), func(5);
    cout << (a == b ? ans : -1) << endl;
    return 0;
}